package ink.lovejinhu.leetcode;

import java.util.HashMap;

public class Solution_0594 {
    public int findLHS(int[] nums) {
        HashMap<Integer, Integer> res = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if (res.containsKey(nums[i])) {
                res.put(nums[i], res.get(nums[i]) + 1);
            } else {
                res.put(nums[i], 1);
            }
        }
        int max = 0;
        for (int v0 : res.keySet()
        ) {
            if (res.containsKey(v0 + 1)) {
                max = Math.max(max, res.get(v0) + res.get(v0 + 1));
            }
        }
        return max;
    }
}
